const IDs = require("../../../../models/system/idsModel.js");
const { buildErrObject } = require("../../../../utils/buildErrObject.js");
const insertID = function (req = {}) {
	return new Promise(async (resolve, reject) => {
		let idsInfo = await IDs.findOne({
			type: req.type,
		});
		const ids = new IDs(req);
		if (idsInfo === null) {
			ids.save((err, item) => {
				if (err) {
					reject(buildErrObject(422, err.message));
				}
				resolve(item);
			});
			return;
		}
		return reject(buildErrObject(422, "类型已存在"));
	});
};

module.exports = { insertID };
